package com.heu.blood.security.controller;

import com.heu.blood.common.aop.ControllerLogAnnotation;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;
import com.heu.blood.security.entity.RoleEntity;
import com.heu.blood.security.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 *
 * @author lrz
 * @email lrz@heu.com
 * @date 2023-08-16 02:58:36
 */
@RestController
@RequestMapping("security/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ControllerLogAnnotation(module = "角色模块", operate = "分页查询角色信息")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = roleService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ControllerLogAnnotation(module = "角色模块", operate = "查询角色信息")
    public R info(@PathVariable("id") Long id){
		RoleEntity role = roleService.getById(id);

        return R.ok().put("role", role);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ControllerLogAnnotation(module = "角色模块", operate = "保存角色信息")
    public R save(@RequestBody RoleEntity role){
		roleService.save(role);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ControllerLogAnnotation(module = "角色模块", operate = "修改角色信息")
    public R update(@RequestBody RoleEntity role){
		roleService.updateById(role);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ControllerLogAnnotation(module = "角色模块", operate = "删除角色信息")
    public R delete(@RequestBody Long[] ids){
		roleService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
